package
{
	import flash.display.Sprite;
	import flash.events.Event;
	import flash.utils.getTimer;
	
	import mx.core.UIComponent;

	public class AnalogClock extends UIComponent
	{
		[Embed(source="assets/clock_asset01.swf",symbol="Bg")]
		private var BgSymbol:Class;
		[Embed(source="assets/clock_asset01.swf",symbol="HoursHand")]
		private var HoursHandSymbol:Class;
		[Embed(source="assets/clock_asset01.swf",symbol="MinutesHand")]
		private var MinutesHandSymbol:Class;
		[Embed(source="assets/clock_asset01.swf",symbol="SecondsHand")]
		private var SecondsHandSymbol:Class;
		
		private var m_bg:Sprite;
		private var m_hoursHand:Sprite;
		private var m_minutesHand:Sprite;
		private var m_secondsHand:Sprite;
		
		private var curTime:Number;
		private var thisTZO:Number;
		private var TZO:Number;
		public function AnalogClock()
		{
			super();
			draw();
			thisTZO = new Date().timezoneOffset;
			TZO=0;
			addEventListener(Event.ENTER_FRAME,enterFrameHandler);
		}
		private function draw():void
		{
			m_bg = new BgSymbol() as Sprite;
			m_hoursHand = new HoursHandSymbol() as Sprite;
			m_minutesHand = new MinutesHandSymbol() as Sprite;
			m_secondsHand = new SecondsHandSymbol() as Sprite;
			
			addChild(m_bg);
			addChild(m_hoursHand);
			addChild(m_minutesHand);
			addChild(m_secondsHand);
			
			var cx:Number,cy:Number;
			cx = m_bg.width/2;
			cy = m_bg.height/2;
			
			m_hoursHand.x=m_minutesHand.x=m_secondsHand.x=cx;
			m_hoursHand.y=m_minutesHand.y=m_secondsHand.y=cy;
		}
		
		private function update():void
		{
			curTime = getTimer();
			var oDate:Date = new Date();
			m_secondsHand.rotation= Utils.convertSecondsToDegree(oDate.seconds);
			m_minutesHand.rotation= Utils.convertMinutesToDegree(oDate.minutes,oDate.seconds);
			m_hoursHand.rotation = Utils.convertHoursToDegree(oDate.hours,oDate.minutes,oDate.seconds);
		}
		private function enterFrameHandler(event:Event):void
		{
			update();
		}
	}
}